class ContactsController < ApplicationController
  
  before_filter :find_contact, :except => [:index, :new, :create]

  def index
    @upcoming_events = Contact.upcoming_events
    @current_contacts = Contact.current_contacts
  end

  def show
    #@tag_list = @contact.tag_list
  end

  def new
    @contact = Contact.new
  end

  def create
    @contact = Contact.new(params[:contact])
   # @contact.tag_list = params[:tag_list].split(",")
    if @contact.save
      flash[:notice] = 'Contact successfully added.'
      redirect_to :action => "index"
    else
      render :action => "new"
    end
  end

  def edit
   # @tag_list = @contact.tag_list
  end

  def update
   # @contact.tag_list = params[:tag_list].split(",")       
    if @contact.update_attributes(params[:contact])
      flash[:notice] = 'Contact Successfully updated.'
      redirect_to :action => "show", :id => params[:id]
    else
      render :action => "edit"
    end
  end

  def destroy
   
    @contact.destroy
    
    flash[:notice] = 'Contact successfully destroyed.'
    redirect_to :action => "index"
  end
  
  private 
  
  def find_contact
    @contact = Contact.find(params[:id])
  end
end
